package org.study.action;

import java.util.Date;
import java.util.List;

import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.study.entity.User;
import org.study.service.IUserService;

/**
 * @author 627266
 * @version 2016年11月22日 下午2:36:42
 * @comment
 */
@Controller()
@RequestMapping(value = "/test")
public class TestAction {
	Logger logger = org.slf4j.LoggerFactory.getLogger(this.getClass());

	@Autowired
	IUserService userService;

	@RequestMapping(value = "findPage", method = RequestMethod.GET)
	@ResponseBody
	private String findPage() {
		return "test";
	}

	@RequestMapping(value = "findList", method = RequestMethod.GET)
	@ResponseBody
	private List<User> findList() {
		logger.info("findList...");
		return userService.findList();
	}

	@RequestMapping(value = "findUser", method = RequestMethod.GET)
	@ResponseBody
	private User selectByPrimaryKey(Long id) {
		return userService.selectByPrimaryKey(id);
	}

	@RequestMapping(value = "delUser", method = RequestMethod.GET)
	@ResponseBody
	private void delByPrimaryKey(Long id) {
		userService.deleteByPrimaryKey(id);
	}

	@RequestMapping(value = "saveUser", method = RequestMethod.GET)
	@ResponseBody
	private String saveUser() {
		User user = new User();
		user.setCreateTm(new Date());
		user.setLoginName("hxj123");
		user.setPassword("123456");
		user.setId(2L);
		userService.saveUserByRedis(user);
		return "save a user";
	}

	@RequestMapping(value = "getUser", method = RequestMethod.GET)
	@ResponseBody
	private User findUser(Long userKey) {
		return userService.getUserByRedis(userKey);
	}

	@RequestMapping(value = "selectByUser", method = RequestMethod.GET)
	@ResponseBody
	private User selectByUser(Long id) {
		User user = new User();	
		user.setId(id);
		return userService.selectByUser(user);
	}

}
